<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>我爱大重庆</title>
    <meta name="keywords" content="重庆新闻,我爱大重庆,重庆,热点新闻,微信资讯" />
    <meta name="description" content="我爱大重庆资讯平台是我爱大重庆公众平台的附属产品，旨在为我爱大重庆的用户提供一个便捷的实时资讯浏览平台" />
    <meta name="viewport" content="width=device-width,initial-scale=1.0,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.4/css/bootstrap.min.css">
    <style>
        body{
            background:#dedede;
        }
        a:link,a:visited,a:hover,a:active{
            color:#333;
        }
        img{
            width:80px;
            height:80px;
            margin-top:10px;
            margin-bottom: 10px;
        }
        blockquote {
            padding: 0px 5px;
            margin: 0 0 0px;
            font-size: 14px;
            border-left: 5px solid #eee;
            max-height: 60px;
            overflow: hidden;
        }
        .list-row{
            margin-top:12px;
            margin-bottom: 12px;
            margin-right:auto;
            margin-left: auto;
            background:#FFF;
            border-radius: 5px;
            height:auto;
            box-shadow: 2px 2px 5px #777;
        }
        .col-lg-12{
            padding-right: 9px;
            padding-left: 9px;
        }
        .col-xs-3{
            padding-right: 5px;
            padding-left: 5px;
        }
        .col-xs-9{
            padding-left:20px;
            padding-right: 5px;
            height:auto;
        }
        .header{
            position: fixed;
            z-index: 9;
            top: 0;
            width:100%;
            height:40px;
            box-shadow: 0px 0px 20px #777;
            background:#FFF;
        }
        .header>button{
            width:100%;
            height: 40px;
            border:0;
            margin:0px auto;
        }
        .margin-bottom{
            height:30px;
        }
        #cover{
            display:none;
            position:absolute;
            left:0;
            top:0;
            z-index:29;
            background-color:#000000;
            opacity:0.7;
        }
        #guide{
            display:none;
            position:absolute;
            right:18px;
            top:5px;
            z-index:29;
        }
        #guide img{
            width: 100%;
            z-index:91;
        }
        h4 {
            font-size: 18px;
            overflow: hidden;
            height: 40px;
            line-height: 1.2;
            margin-top: 15px;
        }
        .bottom{
            bottom: 0;
            margin-bottom: 0px;
            position: absolute;
            right: 7px;
            font-size: 12px;
        }
        .p-label{
            margin: 10px 0 10px;
        }
        .p-label span{
            text-align:center !important;
            padding-top:4px !important;
        }
        .messagecenter{
            font-size: 12px;
            width:20px;
            height:20px;
            line-height:20px;
            background:red;
            font-weight: bold;
            border-radius: 100%;
            color:#FFF;
            display: block;
            position: absolute;
            top:0px;
            right:25px;
        }
    </style>
</head>

<body>


<div id="cover"></div>
<div id="guide"><img src="__PUBLIC__/images/share.png"></div>

<div class="header">
    <button type="button" class="btn btn-default"  style="width:65%;text-align: center;float: left">
        <span class="glyphicon glyphicon-time"></span> 最后更新:{$LastTime|timeFormat=###}
    </button>
    <button type="button" class="btn btn-default"  style="width:35%;text-align: center;float: left">
        <span class="glyphicon glyphicon-envelope mess"></span> <a href="{:U('News/MessageCenter')}">消息</a>
        <?php
            if(!$countread == 0){
                echo "<span class='messagecenter'>".$countread."</span>";
            }else{
        echo "<span class='messagecenter' style='display: none'></span>";
            }
        ?>
    </button>
</div>


<div class="margin-bottom"></div>
<div class="container-fluid">
    <div class="row">
        <div class="col-lg-12">

            <div class="margin-bottom" style="height: 11px !important;"></div>
            <!--置顶-->
            <foreach name="top" item="top">
                <!-------列表------->
                <a href="{:U('News/content','id='.$top['id'])}">
                    <div class="row list-row" style="border-left:2px solid {:RandTopBorder()}">
                        <div class="col-xs-3">
                            <img src="{$top['thumb']}" alt="{$top['title']}" title="{$top['title']}" class="img-rounded">
                        </div>
                        <div class="col-xs-9">
                            <h4>{$top['title']}</h4>
                            <p class="p-label">
                                <?php
                                foreach(label_arr($top['label']) as $key=>$val){
                                echo "<span  class='label label-default ".RandForLabel()."' contenteditable='false'>".$val."</span> ";
                                }
                                ?>
                                <span  class='label label-default ".RandForLabel()."' contenteditable='false'>置顶</span>
                            </p>
                        </div>
                        <div class="col-xs-12" style="margin-top:10px">
                            <div class="bottom">
                            <span class="read">
                                <span class="glyphicon glyphicon-eye-open"></span> {$top['see']}
                            </span>&nbsp;&nbsp;
                            <span class="time">
                                <span class="glyphicon glyphicon-time"></span>{$top['lasttime']|timeFormat=###}
                            </span>
                            </div>
                        </div>
                    </div>
                </a>
                <!-------列表------->
            </foreach>
            <!--最新-->
            <foreach name="list" item="list">
                <!-------列表------->
                <a href="{:U('News/content','id='.$list['id'])}">
                <div class="row list-row" style="border-left:2px solid {:RandTopBorder()}">
                    <div class="col-xs-3">
                        <img src="{$list['thumb']}" alt="{$list['title']}" title="{$list['title']}" class="img-rounded">
                    </div>
                    <div class="col-xs-9">
                        <h4>{$list['title']}</h4>
                        <p class="p-label">
                            <?php
                                foreach(label_arr($list['label']) as $key=>$val){
                                    echo "<span  class='label label-default ".RandForLabel()."' contenteditable='false'>".$val."</span> ";
                                }
                            ?>
                        </p>
                    </div>
                    <div class="col-xs-12" style="margin-top:10px">
                        <div class="bottom">
                            <span class="read">
                                <span class="glyphicon glyphicon-eye-open"></span> {$list['see']}
                            </span>&nbsp;&nbsp;
                            <span class="time">
                                <span class="glyphicon glyphicon-time"></span>{$list['lasttime']|timeFormat=###}
                            </span>
                        </div>
                    </div>
                </div>
                </a>
                <!-------列表------->
            </foreach>
            <div class="before"></div>
        </div>
    </div>
</div>
<span class="limit" style="display: none">20</span>


<img src="__PUBLIC__/images/news-loading.gif" class="loading" style="position: fixed;top:50%;left:50%;margin-left:-40px;margin-top:-40px;display: none ">
<script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://cdn.bootcss.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script>
    //获取滚动条当前的位置
    function getScrollTop() {
        var scrollTop = 0;
        if (document.documentElement && document.documentElement.scrollTop) {
            scrollTop = document.documentElement.scrollTop;
        }
        else if (document.body) {
            scrollTop = document.body.scrollTop;
        }
        return scrollTop;
    }

    //获取当前可是范围的高度
    function getClientHeight() {
        var clientHeight = 0;
        if (document.body.clientHeight && document.documentElement.clientHeight) {
            clientHeight = Math.min(document.body.clientHeight, document.documentElement.clientHeight);
        }
        else {
            clientHeight = Math.max(document.body.clientHeight, document.documentElement.clientHeight);
        }
        return clientHeight;
    }
    //获取文档完整的高度
    function getScrollHeight() {
        return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
    }

</script>
<script>
    $(function(){
        window.onscroll = function () {
            if (getScrollTop() + getClientHeight() == getScrollHeight()) {
                var column = "{:I('column')}";
                var limit = $('.limit').html();
                $('.loading').show();
                $.post('{:U("News/index")}', {column:column,limit: limit }, function (data) {
                    var obj = eval('('+data+')');
                    var tpl = '';
                    for(var a in obj){
                        tpl += "<a href='/DaChongQing/news/content/id/"+obj[a]['id']+"'> " +
                                    "<div class='row list-row' style='border-left:2px solid "+border()+"'> " +
                                        "<div class='col-xs-3'> " +
                                            "<img src='"+obj[a]['thumb']+"' alt='"+obj[a]['title']+"' title='"+obj[a]['title']+"' class='img-rounded'> " +
                                        "</div> " +
                                        "<div class='col-xs-9'> " +
                                        "<h4>"+obj[a]['title']+"</h4> " +
                                        "<p class='p-label'> " +
                                            label(obj[a]['label'])+
                                        "</p> " +
                                    "</div> " +
                                    "<div class='col-xs-12' style='margin-top:10px'> " +
                                    "<div class='bottom'> " +
                                        "<span class='read'> " +
                                            "<span class='glyphicon glyphicon-eye-open'></span> "+obj[a]['see']+" " +
                                        "</span>&nbsp;&nbsp; " +
                                        "<span class='time'> " +
                                            "<span class='glyphicon glyphicon-time'></span> "+getDateDiff(obj[a]['lasttime'])+"" +
                                        "</span> " +
                                    "</div> " +
                                "</div> " +
                                "</div> " +
                        "</a>";
                    }
//                    alert(obj);
                    $('.before').before(tpl);
                    $('.loading').hide();
                    $('.limit').html(parseInt(limit)+parseInt(20))
                });
            }
        }
        function Message(){
            $.post("{:U('News/read')}",function(data){
               $('.messagecenter').html(data);
                $('.messagecenter').show();
                if(data == 0){
                    $('.messagecenter').hide();
                }
            })
        }
        window.setInterval(Message,5000);
    })
    function getDateDiff(dateTimeStamp){
        var minute = 1000 * 60;
        var hour = minute * 60;
        var day = hour * 24;
        var month = day * 30;
        var now = new Date().getTime();
        var diffValue = parseInt(now) - parseInt(dateTimeStamp+'000');
//            alert(diffValue)
        if(diffValue < 0){
            //若日期不符则弹出窗口告之
            //alert("结束日期不能小于开始日期！");
        }
        var monthC =diffValue/month;
        var weekC =diffValue/(7*day);
        var dayC =diffValue/day;
        var hourC =diffValue/hour;
        var minC =diffValue/minute;
        if(dayC>=1){
            result= parseInt(dayC) +"天前";
        }
        else if(hourC>=1){
            result= parseInt(hourC) +"小时前";
        }
        else if(minC>=1){
            result= parseInt(minC) +"分钟前";
        }else
            result="刚刚发表";
        return result;
    }
    function LabelB(){
        var LabelB = ["label-info", "label-danger", "label-success", "label-warning", "label-primary"];
        var index = Math.floor((Math.random()*LabelB.length));
        return LabelB[index];
    }
    function border(){
        var border = ['red','blue','green','yellow','black','#FFF68F','#FFC1C1','#FF7F00','#FF8C69','#FF4500',
                      '#FF00FF','#EE9A49','#EE6A50','#D15FEE','#CD919E','#BCEE68','#B0E2FF','#AB82FF','#A020F0','#8DEEEE',
                      '#548B54','#545454','#53868B','#528B8B','#525252', '#515151', '#4F94CD', '#4F4F4F', '#4EEE94', '#4D4D4D',
                        '#4B0082', '#4A708B', '#4A4A4A', '#48D1CC', '#4876FF', '#483D8B', '#474747', '#473C8B', '#4682B4', '#458B74',
                     '#458B00', '#454545', '#43CD80', '#436EEE', '#424242', '#4169E1', '#40E0D0', '#404040', '#3D3D3D', '#3CB371',
                    '#3B3B3B', '#3A5FCD', '#388E8E', '#383838', '#36648B', '#363636', '#333333', '#32CD32', '#303030', '#2F4F4F',
                    '#2E8B57', '#2E2E2E', '#2B2B2B', '#292929', '#282828', '#27408B', '#262626', '#242424', '#228B22', '#218868',
                '#212121', '#20B2AA', '#1F1F1F', '#1E90FF', '#1E1E1E', '#1C86EE', '#1C1C1C', '#1A1A1A', '#191970', '#1874CD',
                '#171717', '#141414', '#121212', '#104E8B', '#0F0F0F', '#0D0D0D', '#0A0A0A', '#080808', '#050505', '#030303',
            '#00FFFF', '#00FF7F', '#00FF00', '#00FA9A', '#00F5FF', '#00EEEE', '#00EE76', '#00EE00', '#00E5EE', '#00CED1',
            '#00CDCD', '#00CD66', '#00CD00'];
        var index = Math.floor((Math.random()*border.length));
        return border[index];
    }
    function label(label){
        var arr = label.split('%');
        var str = '';

        for(var i = 0; i < arr.length;i++){
            str += "<span class='label label-default "+LabelB()+"' contenteditable='false'>"+arr[i]+"</span> ";
        }
        return str;
    }
</script>
</body>
</html>